package com.heima.article.controller.v1;

import com.heima.article.service.IArticleService;
import com.heima.model.article.dtos.ApArticleDto;
import com.heima.model.article.dtos.ArticlePageDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Type;

@RestController
@RequestMapping("/api/v1/article")
@RequiredArgsConstructor
public class ArticleController {
    private final IArticleService articleService;

    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticlePageDto dto) {
        Integer type = 0;
        return ResponseResult.okResult(articleService.getPage(type, dto));
    }

    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticlePageDto dto) {
        Integer type = 1;
        return ResponseResult.okResult(articleService.getPage(type, dto));
    }

    @PostMapping("/loadmore")
    public ResponseResult loadmore(@RequestBody ArticlePageDto dto) {
        Integer type = 2;
        return ResponseResult.okResult(articleService.getPage(type, dto));

    }

    /**
     * 发布文章
     * @param apArticleDto
     * @return
     */
    @PostMapping("/save")
    public ApArticle saveArticle(@RequestBody ApArticleDto apArticleDto){
        return  articleService.saveArticle(apArticleDto);
    }
}
